package com.linshen.grpcspringcloudprovider;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

import io.envoyproxy.pgv.ReflectiveValidatorIndex;
import io.envoyproxy.pgv.ValidatorIndex;
import io.envoyproxy.pgv.grpc.ValidatingServerInterceptor;
import io.grpc.ServerInterceptor;
import net.devh.boot.grpc.server.interceptor.GrpcGlobalServerInterceptor;

@SpringBootApplication
@EnableDiscoveryClient
public class GrpcSpringCloudProviderApplication {

    public static void main(String[] args) {
        SpringApplication.run(GrpcSpringCloudProviderApplication.class, args);
    }

    @GrpcGlobalServerInterceptor
    ServerInterceptor logServerInterceptor() {
        return new MainGrpcInterceptor();
    }

    @GrpcGlobalServerInterceptor
    ServerInterceptor validateInterceptor(){
        ValidatorIndex reflectiveValidatorIndex = new ReflectiveValidatorIndex();
        return new ValidatingServerInterceptor(reflectiveValidatorIndex);
    }

}
